package com.right.health.app.ui.me.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hyphenate.util.DateUtils;
import com.magic.basic.adapter.BaseAbsAdapter;
import com.magic.basic.utils.DateFormatUtil;
import com.right.health.app.R;
import com.right.health.app.bean.MyServiceBean;
import com.right.health.app.utils.TimeUtils;

import java.util.Date;

/**
 * @author: weming
 * @date: 2021/5/7
 * @description:
 */
public class MyServiceAdapter extends BaseAbsAdapter<MyServiceBean> {

    private View.OnClickListener mClickListener;

    public MyServiceAdapter(Context context) {
        super(context);
    }

    public void setClickListener(View.OnClickListener clickListener) {
        mClickListener = clickListener;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_my_service, null);
            viewHolder = new ViewHolder();
            viewHolder.mTimeTv = convertView.findViewById(R.id.tv_time);
            viewHolder.mTitleTv = convertView.findViewById(R.id.tv_title);
            viewHolder.mStateTv = convertView.findViewById(R.id.tv_state);
            viewHolder.mOperateTV = convertView.findViewById(R.id.tv_complete);
            viewHolder.mPriceTv = convertView.findViewById(R.id.tv_price);
            if (mClickListener!=null)
            viewHolder.mOperateTV.setOnClickListener(mClickListener);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MyServiceBean bean = getDataSource().get(position);

        viewHolder.mTimeTv.setVisibility(View.VISIBLE);
        viewHolder.mOperateTV.setVisibility(View.VISIBLE);
        viewHolder.mStateTv.setVisibility(View.VISIBLE);
        Log.i("MYTAG", "getView: "+bean.getPaytime());
        if (bean.getPaytime()>0) {
            viewHolder.mTimeTv.setText("购买时间：" + DateFormatUtil.formatDate(new Date(bean.getPaytime()),"yyyy-MM-dd HH:mm"));
        }
        if (bean.getOrderstatus().equals("0")) {
            viewHolder.mStateTv.setText("未付款");
            viewHolder.mOperateTV.setText("去付款");
        } else if (bean.getOrderstatus().equals("1")) {
            viewHolder.mStateTv.setText("服务中");
            viewHolder.mOperateTV.setText("查看");
        } else {
            viewHolder.mStateTv.setText("完成服务");
            viewHolder.mOperateTV.setText("查看");
        }
        viewHolder.mOperateTV.setTag(bean);
        viewHolder.mTitleTv.setText(bean.getPkname());
        viewHolder.mPriceTv.setText("￥" + bean.getPkprice());
        return convertView;
    }

    static class ViewHolder {
        private TextView mTitleTv, mTimeTv, mStateTv, mOperateTV, mPriceTv;
    }
}
